﻿using AutoMapper;
using MediatR;
using Traceability.APP.Application.Command.Breeds;
using Traceability.APP.Application.Command.Traceablitys;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Breeds
{
    public class DeleteImmunityCommandHadLer : IRequestHandler<DeleteImmunityCommand, APIResult<int>>
    {

        private readonly IBaseRepostiy<Immunity> _immunity;


        public DeleteImmunityCommandHadLer(IBaseRepostiy<Immunity> immunity)
        {
            this._immunity = immunity;
        }
        public async Task<APIResult<int>> Handle(DeleteImmunityCommand request, CancellationToken cancellationToken)
        {

            APIResult<int> result = new APIResult<int>();
            var list =_immunity.GetAll().FirstOrDefault(x => x.Id == request.Id);
            list.DeleteUserTime = DateTime.Now;
            list.IsDeleted = true;
            var res = await _immunity.Update(list);
            result.Code = ResultCode.Ok;

            result.Message = "免疫信息删除成功";
            result.Data = res;
            return await Task.FromResult(result);
        }
    }
}
